//
//  MyCollectionViewCell.swift
//  Venus
//
//  Created by qurongxiang on 2018/7/23.
//  Copyright © 2018年 zhaowang. All rights reserved.
//

import UIKit
import SwiftyJSON

class MyCollectionViewCell: UICollectionViewCell {
    
    fileprivate lazy var imgView =  UIImageView()
    fileprivate lazy var titleLabel = UILabel(kColorC5, 14, "标题")
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension MyCollectionViewCell {
    func congfigModel(modelArr:[[String:String]] ,index:IndexPath , numModel:ShowNumModel) {
        let json = JSON(modelArr[index.item])
        imgView.image = UIImage(named: json["img"].string!)
        titleLabel.text = json["title"].string
        imgView.viewWithTag(100)?.removeFromSuperview()
        if index.item == 1 { //消息通知
            addNumLabel(num: numModel.notifyMsgNum)
        }
        
        if index.item == 4 { //我的预约
            addNumLabel(num: numModel.appointmentMsgNum)
        }
    }
    
    
    /// 显示消息的数量
    ///
    /// - Parameter num: <#num description#>
    func addNumLabel(num:Int) {
        let numLabl = UILabel(num: num, point: CGPoint.zero)
        imgView.addSubview(numLabl)
        numLabl.x = self.contentView.width -   numLabl.height - 15
        numLabl.y = 10
        numLabl.tag = 100
    }
}

extension MyCollectionViewCell {
    func setupUI() {
        contentView.addSubview(imgView)
        contentView.addSubview(titleLabel)
        imgView.snp.makeConstraints { (make) in
            make.left.top.right.equalToSuperview()
            make.bottom.equalToSuperview().inset(25)
        }
        imgView.contentMode = .scaleAspectFit
        imgView.image = UIImage(named: "my_collection")
        
        titleLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().inset(5)
        }
    }
}
